package com.buercorp.wangyu.core1.ch9.treeSet;

import java.util.*;

/**
 * This program sorts a set of Item objects by comparing their descriptions.
 *
 * @author Cay Horstmann
 * @version 1.13 2018-04-10
 */
public class TreeSetTest {
    public static void main(String[] args) {
        // 创建集合对象
//        var parts = new TreeSet<Item>();
        TreeSet<Item> parts = new TreeSet<>();

        parts.add(new Item("Abaster", 1234));
        parts.add(new Item("Abdem", 9912));
        parts.add(new Item("Acdget", 4562));

        // 指定排序 数字从小到大排 Comparable接口
        System.out.println("集合中有" + parts);

        // ???
        var sortByDescription = new TreeSet<Item>(Comparator.comparing(Item::getDescription));
        // 用于比较Item对象的description属性 将Item类的getDescription方法作为比较依据

        sortByDescription.addAll(parts);
        System.out.println(sortByDescription);
    }
}
